#!/bin/bash

echo "========================================"
echo "若依系统Docker构建脚本"
echo "========================================"

echo "1. 清理Maven项目..."
mvn clean
if [ $? -ne 0 ]; then
    echo "Maven清理失败！"
    exit 1
fi

echo "2. 编译打包项目..."
mvn package -Dmaven.test.skip=true
if [ $? -ne 0 ]; then
    echo "Maven打包失败！"
    exit 1
fi

echo "3. 检查JAR文件是否存在..."
if [ ! -f "ruoyi-admin/target/ruoyi-admin.jar" ]; then
    echo "JAR文件不存在，请检查编译是否成功！"
    exit 1
fi

echo "4. 构建Docker镜像..."
docker build -t ruoyi:latest .
if [ $? -ne 0 ]; then
    echo "Docker镜像构建失败！"
    exit 1
fi

echo "5. 显示构建的镜像..."
docker images | grep ruoyi

echo "========================================"
echo "构建完成！"
echo "使用以下命令启动服务："
echo "docker-compose up -d"
echo "========================================"